using System;
using System.Collections.Generic;
using System.Text;
using Ares.PacketHandlers;

namespace cb0tServer
{
    class SCASOutboundPackets
    {
        public static byte[] LoginAck()
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(CoreSettings.scas_version);
            return p.ToAresPacket(2);
        }

        public static byte[] UserListItem(UserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(userobj.name);
            p.WriteString(userobj.version);
            p.WriteIP(userobj.physical_ip);
            p.WriteByte(userobj.level);
            p.WriteByte(userobj.host ? (byte)1 : (byte)0);
            p.WriteInt16(userobj.vroom);
            return p.ToAresPacket(3);
        }

        public static byte[] UserListEnd()
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteByte(0);
            return p.ToAresPacket(4);
        }

        public static byte[] UpdateUserItem(UserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(userobj.name);
            p.WriteString(userobj.version);
            p.WriteIP(userobj.physical_ip);
            p.WriteByte(userobj.level);
            p.WriteByte(userobj.host ? (byte)1 : (byte)0);
            p.WriteInt16(userobj.vroom);
            return p.ToAresPacket(5);
        }

        public static byte[] JoinedItem(UserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(userobj.name);
            p.WriteString(userobj.version);
            p.WriteIP(userobj.physical_ip);
            p.WriteByte(userobj.level);
            p.WriteByte(userobj.host ? (byte)1 : (byte)0);
            p.WriteInt16(userobj.vroom);
            return p.ToAresPacket(6);
        }

        public static byte[] PartedItem(UserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            return p.ToAresPacket(7);
        }

        public static byte[] MainTopic()
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(Topics.GetMainTopic(true), false);
            return p.ToAresPacket(10);
        }

        public static byte[] MainUrl()
        {
            AresDataPacket p = new AresDataPacket();

            if (UrlTag.Enabled)
            {
                p.WriteString(UrlTag.Url);
                p.WriteString(UrlTag.Tag);
            }
            else
            {
                p.WriteBytes(new byte[] { 0, 0 });
            }

            return p.ToAresPacket(20);
        }

        public static byte[] PublicText(UserObject userobj, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(text, false);
            return p.ToAresPacket(40);
        }

        public static byte[] EmoteText(UserObject userobj, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(text, false);
            return p.ToAresPacket(41);
        }

        public static byte[] MuzzleText(UserObject userobj, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(text, false);
            return p.ToAresPacket(42);
        }

        public static byte[] CommandText(String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(text, false);
            return p.ToAresPacket(45);
        }

        public static byte[] HostPM(UserObject userobj, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteInt16(userobj.id);
            p.WriteString(text, false);
            return p.ToAresPacket(50);
        }

        public static byte[] LinkUserListItem(LinkedUserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(userobj.name, false);
            return p.ToAresPacket(60);
        }

        public static byte[] LinkJoinedItem(LinkedUserObject userobj)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(userobj.name, false);
            return p.ToAresPacket(61);
        }

        public static byte[] LinkPartedItem(String name)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(name, false);
            return p.ToAresPacket(62);
        }

        public static byte[] LinkPublicText(String name, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(name);
            p.WriteString(text, false);
            return p.ToAresPacket(63);
        }

        public static byte[] LinkEmoteText(String name, String text)
        {
            AresDataPacket p = new AresDataPacket();
            p.WriteString(name);
            p.WriteString(text, false);
            return p.ToAresPacket(64);
        }

    }
}
